package com.shihb.behavioralpatterns;/**
 *Description:模板模式
 *Version:1.0.0
 *@author shihb
 *@date 2020/4/21 11:25
 */
public class TemplatePattern {

  public static void main(String[] args) {
    SoybeanMilk redSoyabeanMilk = new RedSoyabeanMilk();
    SoybeanMilk greenSoyabeanMilk = new GreenSoyabeanMilk();
    SoybeanMilk pureSoyabeanMilk = new PureSoyabeanMilk();
    System.out.println("-----红豆豆浆------");
    redSoyabeanMilk.make();
    System.out.println("-----绿豆豆浆------");
    greenSoyabeanMilk.make();
    System.out.println("-----原味豆浆------");
    pureSoyabeanMilk.make();

  }
}
abstract class SoybeanMilk{
  // 让子类无法覆盖
  final void make(){
    //定义模板
    select();
    add();
    soak();
    polish();
  }
  private void select(){
    System.out.println("精选上好黄豆");
  }

  //让子类具体实现
  abstract void add();
  private void soak(){
    System.out.println("进行充分的浸泡");
  }

  private void polish(){
    System.out.println("放入豆浆机打磨");
  }
}


class RedSoyabeanMilk extends SoybeanMilk{

  @Override
  void add() {
    System.out.println("加入精选上好红豆");
  }
}
class GreenSoyabeanMilk extends SoybeanMilk{

  @Override
  void add() {
    System.out.println("加入精选上好绿豆");
  }
}
class PureSoyabeanMilk extends SoybeanMilk{


  @Override
  void add() {

  }
}
